<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">新闻名称</label>
        <div class="layui-input-block">
            <input type="text" id="news_name" name="news_name"  class="layui-input" autocomplete="off" lay-verify="required">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">新闻内容</label>
        <div class="layui-input-block">
            <textarea id="news_content" name="news_content" class="layui-textarea" ></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">选择审核人</label>
        <div class="layui-input-block">
            <select name="review_user" lay-filter="aihao" id="review_user">

            </select>
        </div>
    </div>

    <input type="hidden" name="userId" id="userId" />
    <input type="hidden" name="news_state" value="审核中"/>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/common.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

                $.ajax({
                    type:"post",
                    dataType:"json",
                    url: webUrl+'/news/news_add',//url
                    contentType: "application/json; charset=utf-8",
                    data:JSON.stringify(data.field),
                    success: function (result) {
                        if (result.data.success == true) {
                            layer.msg("操作成功");

                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            window.parent.location.reload();
                        } else {
                            layer.msg("操作失败");
                        }
                    },
                    error: function () {
                        layer.msg("操作失败");
                    }

                })


            return false;
        });

        /**
         * 获取用户
         */
        $.ajax({
            type:"post",
            dataType:"json",
            url: webUrl+'/user/getUserList',//url
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                if (result.data.success==true) {
                    var option='<option value=""></option>'
                    for(var i=0;result.data.rows.length>i;i++){
                        var id=result.data.rows[i].id;
                        var name=result.data.rows[i].firstName+result.data.rows[i].lastName;
                        option+='<option value="'+id+'">'+name+'</option>';
                    }
                    $("#review_user").html(option);
                    form.render();
                } else {
                    layer.msg("操作失败");
                }
            },
            error: function () {
                layer.msg("操作失败");
            }

        })

       $("#userId").val(window.localStorage.getItem("userId"));

    });



</script>
</body>
</html>